package com.yangrong.thread.chapter11;

/**
 * 用线程保险箱ThreadLocal优化上线文设计模式，避免将context从头传到尾
 * 
 * @author YangRong
 * @date 2020年6月12日
 */
public final class ActionContext {

	private static final ThreadLocal<Context> THREAD_LOCAL = new ThreadLocal<Context>() {
		protected Context initialValue() {
			return new Context();
		}
	};

	private static class ContextHolder {
		private final static ActionContext ACTION_CONTEXT = new ActionContext();
	}

	public static ActionContext getActionContext() {
		return ContextHolder.ACTION_CONTEXT;
	}

	public Context getContext() {
		return THREAD_LOCAL.get();
	}
}
